package cn.east196.tfx.controller;



import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.jfinal.kit.PropKit;

import cn.east196.xfx.StagePool;
import cn.east196.xfx.controls.MessageBox;
import cn.edu.scau.biubiusuisui.annotation.FXBind;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXData;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.ComboBox;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextField;
import javafx.scene.control.PasswordField;
import javafx.scene.control.Button;
import javafx.scene.control.TreeView;

@FXController(path = "fxml/initializers.fxml")
@FXWindow(mainStage = true, title = "Initializer")
public class InitializerController extends FXBaseController {

	protected static Logger logger = LogManager.getLogger(InitializerController.class);

	@FXML
	private MenuItem aboutMenu;

	@FXML
	private ComboBox dbTypeComboBox;

	@FXML
	private ComboBox urlComboBox;

	@FXML
	private TextField userNameField;

	@FXML
	private PasswordField passowrdField;

	@FXML
	private Button connButton;

	@FXML
	private TreeView dbTree;

	@FXData
	@FXBind({ // 注意是单向绑定，直接initConfig.setXXXName会报错
			"url=${urlComboBox.value}", // url
			"url=${urlComboBox.value}", // url
			"name=${userNameField.text}", // 名称
			"password=${passowrdField.text}",// 密码
	})
	private InitializerEntity initConfig = new InitializerEntity();

	public void initialize() throws Exception {
		urlComboBox.setValue(PropKit.get("jdbc.url","")); // 找属性： 模块.字段 or ""
		userNameField.textProperty().set(PropKit.get("jdbc.username")); 
		passowrdField.textProperty().set(PropKit.get("jdbc.password"));
	}

	@FXML
	public void initConn() {
		System.out.println("initConn");
		System.out.println(initConfig);
	}

	@FXML
	public void about() {
		MessageBox.showResult(StagePool.get("main"), Alert.AlertType.INFORMATION, "About",
				String.format("%s (%s)", PropKit.get("app.title"), PropKit.get("app.version")));
	}
}
